/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fourbox;


/**
 *
 * @author hartono
 */
public class ClientProtocol {
    
    public static final int LOGIN_FAILED = -1;
    public static final int LOGIN_SUCCESS = 1;
    public static final int START_CONNECTED=2;
    public static final int CONNECTION_ALIVE = 3;
    
    public static final int THERE_ARE_UPDATE =4; // ada perubahan dari server, suruh client update
    public static final int SHOULD_COMMIT = 5;
        
    
    
    public  int clientProcess(byte[] message){
        int messageID = message[0];        
        if (messageID == ProtocolMessage.SERVER_ACK_LOGIN){
            // ack login            
            boolean success = (message[1] == (byte)1);            
            if (success){                
                System.out.println("Protocol : message name = ACK LOGIN SUCCESS");
                return LOGIN_SUCCESS;
            }else{
                System.out.println("Protocol : message name = ACK LOGIN FAILED");
                return LOGIN_FAILED;
            }
            
        }else if(messageID == ProtocolMessage.SERVER_MSG_CONNECTED){
            // ack from server, client and server connected            
            System.out.println("Protocol : message name = SERVER MSG CONNECTED");
            return START_CONNECTED;
        }else if(messageID == ProtocolMessage.SERVER_ACK_KEEP_ALIVE){
            // ack from server, client and server connected            
//            System.out.println("Protocol : message name = SERVER ACK CONNECTED");
            return CONNECTION_ALIVE;
        }else if (messageID == ProtocolMessage.SERVER_MSG_UPDATE){
            
            return THERE_ARE_UPDATE;
        }else if (messageID == ProtocolMessage.SERVER_ACK_MSG_LIST_FILES_REGULAR){
            return SHOULD_COMMIT;
        }
        
        return -1;
    }
    
}
